{{#ifInList type 'array,map'}}
  {{#each children}}
    <div class="dualValue">
      <a class="btn btn-default btn-xs btn-inline" tabindex="-1" onclick="htmlapi.subRemove(this);"><i class="glyphicon glyphicon-minus"></i></a>
      {{>field.hbs}}
    </div>
  {{/each}}
{{/ifInList}}

{{#if field.required}}
  <span class="required">
{{/if}}

{{#if parentIsMap}}
  {{#if formFieldName2}}
    <input type="text" class="form-control key" name="{{formFieldName2}}" value="{{value2}}" />&nbsp;:&nbsp;
  {{/if}}
{{/if}}

{{#ifInList type 'string,date,base64,dnsLabel,dnsLabelRestricted,hostname'}}
  <input type="text" class="form-control" name="{{formFieldName}}" value="{{value}}" placeholder="{{placeholder}}"/>
{{/ifInList}}

{{#ifEqual type 'json'}}
  <textarea class="form-control" name="{{formFieldName}}">{{value}}</textarea>
{{/ifEqual}}

{{#ifInList type 'password,masked'}}
  <input type="password" class="form-control" name="{{formFieldName}}" value="{{value}} placeholder="{{placeholder}}" />
{{/ifInList}}

{{#ifInList type 'number,int,float'}}
  <input 
    type="number"
    class="form-control"
    name="{{formFieldName}}"
    value="{{value}}"
    placeholder="{{placeholder}}"
    {{#ifEqual field.min undefined}} {{else}} min="{{field.min}}"{{/ifEqual}}
    {{#ifEqual field.max undefined}} {{else}} max="{{field.max}}"{{/ifEqual}}
    {{#if field.step}} step="{{field.step}}"{{/if}}
  />
{{/ifInList}}

{{#ifEqual type "blob"}}
  <input type="file" class="form-control" name="{{formFieldName}}" />
{{/ifEqual}}

{{#ifEqual type "boolean"}}
  {{#if field.nullable}}
    <select name="{{formFieldName}}" class="form-control">
      <option value="__-*NULL*-__" {{#ifEqual null ../value}} SELECTED{{/ifEqual}}>NULL</option>
      <option value="" {{#ifEqual false ../value}} SELECTED{{/ifEqual}}>false</option>
      <option value="1" {{#ifEqual true ../value}} SELECTED{{/ifEqual}}>true</option>
    </select>
  {{else}}
    <input type="checkbox" class="form-control" name="{{formFieldName}}" value="1" {{#if value}} CHECKED{{/if}} />
  {{/if}}
{{/ifEqual}}

{{#ifEqual type "enum"}}
  <select name="{{formFieldName}}" class="form-control">
    {{#if field.nullable}}
      <option value="__-*NULL*-__">NULL</option>
    {{/if}}
    {{#each field.options}}
      <option value="{{this}}" {{#ifEqual this ../value}} SELECTED{{/ifEqual}}>{{this}}</option>
    {{/each}}
  </select>
{{/ifEqual}}

{{#ifEqual type "reference"}}
  {{#if field.options}}
    <select name="{{formFieldName}}" class="form-control">
      {{#if field.nullable}}
        <option value="__-*NULL*-__">NULL</option>
      {{/if}}
      {{#eachProperty field.options}}
        <option value="{{key}}" {{#ifEqual key ../value}} SELECTED{{/ifEqual}}>{{value}}</option>
      {{/eachProperty}}
      {{#ifInMap value field.options}}
      {{else}}
        <option value="{{value}}" SELECTED>{{value}}</option>
      {{/ifInMap}}
    </select>
  {{else}}
    <input type="text" class="form-control" name="{{formFieldName}}" value="{{value}}">
  {{/if}}
{{/ifEqual}}

{{#ifEqual type "__type__"}}
  <select name="{{formFieldName}}" class="form-control" onchange="htmlapi.createTypeChanged($(this).val());">
    {{#each field.options}}
      <option value="{{this}}" {{#ifEqual this ../value}} SELECTED{{/ifEqual}}>{{this}}</option>
      <!-- {{this}} , {{../value}} -->
    {{/each}}
  </select>
{{/ifEqual}}

{{#if field.required}}
  </span>
{{/if}}

{{#if enlargeable}}
  <a class="btn btn-default btn-xs btn-inline" onclick="htmlapi.switchToTextarea(this);" tabindex="-1" title="Enlarge"><i class="glyphicon glyphicon-resize-full"></i></a>
{{/if}}

{{#if nullCheck}}
  <div class="nullcheck">
    <label>
      <input type="checkbox" name="{{formFieldNameNull}}" value="1" tabindex="-1" onclick="htmlapi.toggleNull(this);" {{#ifEqual null value}} CHECKED{{/ifEqual}}>NULL
    </label>
  </div>
{{/if}}

{{#unless addingField}}
  {{#ifInList type 'array,map'}}
      <a class="btn btn-default btn-xs btn-inline" tabindex="-1" onclick="htmlapi.subAdd(this,'{{name}}');"><i class="glyphicon glyphicon-plus"></i></a>
    </div>
  {{/ifInList}}
{{/unless}}
